//
//  ModifyPersonalRemarkView.m
//  PigMarket
//
//  Created by Felix on 2019/3/15.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "ModifyPersonalRemarkView.h"

#import "MyTextView.h"

@interface ModifyPersonalRemarkView ()<UITextViewDelegate>

/**
 bgView
 */
@property (nonatomic , strong) UIView *inputBgView;
/**
 titleLab
 */
@property (nonatomic , strong) UILabel *titleLab;
/**
 textView
 */
@property (nonatomic , strong) MyTextView *remarkTextView;

/**
 limitWord
 */
@property (nonatomic , strong) UILabel *limitWord;

/**
 inputCount
 */
@property (nonatomic , assign) NSInteger inputCount;

/**
 saveBtn
 */
@property (nonatomic , strong) UIButton *saveBtn;
@end

@implementation ModifyPersonalRemarkView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.inputBgView];
    [self addSubview:self.titleLab];
    [self.inputBgView addSubview:self.remarkTextView];
    [self.inputBgView addSubview:self.limitWord];
    [self addSubview:self.saveBtn];
}

- (void)initLayout {
    // 布局子控件

    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(20);
        make.top.mas_offset(15);
        make.width.mas_offset(SCREEN_WIDTH - 20);
    }];
    
    [self.inputBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(15);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(185);
    }];
    [self.remarkTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(150);
    }];
    [self.limitWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(self.remarkTextView.mas_bottom).offset(12);
        make.width.mas_equalTo(200);
    }];
    [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.inputBgView.mas_bottom).offset(60);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(48);
        make.bottom.mas_equalTo(0);
    }];
}
- (void)textViewDidChange:(UITextView *)textView {
    self.inputCount = textView.text.length;
    self.limitWord.text = [NSString stringWithFormat:@"%ld/100",(long)self.inputCount];
}
#pragma mark - getter and setter
- (UIView *)inputBgView {
    if (!_inputBgView) {
        _inputBgView = [[UIView alloc] init];
        _inputBgView.backgroundColor = [UIColor globalBackgroundColor];
    }
    return _inputBgView;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.text = @"个性签名";
        _titleLab.textColor = [UIColor textBlackColor];
        _titleLab.font = [UIFont largerFont];
        }
    return _titleLab;
}
- (MyTextView *)remarkTextView {
    if (!_remarkTextView) {
        _remarkTextView = [[MyTextView alloc] init];
        _remarkTextView.textColor = [UIColor textBlackColor];
        _remarkTextView.editable = YES;
        _remarkTextView.delegate = self;
        _remarkTextView.scrollEnabled = YES;
        _remarkTextView.backgroundColor = [UIColor globalBackgroundColor];
        _remarkTextView.placeholder = @"请输入个性签名";
        _remarkTextView.placeholderColor = [UIColor colorWithHexString:@"#999999"];
    }
    return _remarkTextView;
}
- (UILabel *)limitWord {
    if (!_limitWord) {
        _limitWord = [[UILabel alloc] init];
        _limitWord.textColor = [UIColor colorWithHexString:@"#CCCCCC"];
        _limitWord.text = @"0/100";
        _limitWord.textAlignment = NSTextAlignmentRight;
        _limitWord.font = [UIFont middleFont];
    }
    return _limitWord;
}
- (UIButton *)saveBtn {
    if (!_saveBtn) {
        _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_saveBtn setBackgroundImage:[UIImage imageNamed:@"btn_nomal_bg"] forState:UIControlStateNormal];
    }
    return _saveBtn;
}
@end
